package com.plian.system.service.fr.internalauditmanagement.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.Tools.DateUtil;
import com.plian.Tools.StringUtil;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.entity.fr.internalauditmanagement.*;
import com.plian.system.entity.sys.Dict;
import com.plian.system.mapper.fr.internalauditmanagement.*;
import com.plian.system.mapper.sys.DictMapper;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.service.fr.internalauditmanagement.IamReportService;
import com.plian.system.service.sys.code.IFormCodeService;
import com.plian.system.vo.fr.internalauditmanagement.IamAuditRectifyVO;
import com.plian.system.vo.fr.internalauditmanagement.IamWorkYearAuditProjectVO;
import com.plian.system.vo.report.HeaderVO;
import com.plian.system.vo.report.ReportReturnVO;
import com.plian.system.vo.report.ReportVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;


@Service
@Slf4j
@AllArgsConstructor
public class IamReportServiceImpl implements IamReportService {


    @Resource
    private IamAuditRectifyMapper auditRectifyMapper;
    @Resource
    private IamRectifyTargetListMapper targetListMapper;
    @Resource
    private IamRectifyIdentifyListMapper identifyListMapper;
    @Resource
    private IamRectifyIssureListMapper issureListMapper;
    @Resource
    private IamRectifyReformListMapper reformListMapper;

    private final IamWorkYearAuditProjectMapper auditProjectMapper;

//    private IamAuditRectifyService rectifyService;
//    private IamRectifyIssureListService issureListService;
//    private IamRectifyTargetListService targetListService;
//    private IamRectifyReformListService reformListService;
//    private IamRectifyIdentifyListService identifyListService;

    private DictMapper dictMapper;

    private IFormCodeService formCodeService;

    @Override
    public R<ReportReturnVO> internalAuditProjectData(IamWorkYearAuditProjectVO auditProjectVO) {

        String fillingYear = auditProjectVO.getFillingYear();
        if (StringUtil.isEmpty(fillingYear)) {
            throw new MyRuntimeException(new ObjResult("年份不能为空"));
        }
        List<String> enterpriseIds = auditProjectVO.getEnterpriseIds();

        if (CollectionUtil.isEmpty(enterpriseIds)) {
            throw new MyRuntimeException(new ObjResult("企业不能为空"));
        }

        List<IamWorkYearAuditProject> auditProjects = auditProjectMapper.selectList(new LambdaQueryWrapper<IamWorkYearAuditProject>()
                .in(IamWorkYearAuditProject::getEnterpriseId, enterpriseIds)
                .eq(IamWorkYearAuditProject::getIsPlan, auditProjectVO.getIsPlan()));
        List<IamWorkYearAuditProject> data = new ArrayList<>();

        Map<String, List<IamWorkYearAuditProject>> map = auditProjects.stream().collect(Collectors.groupingBy(IamWorkYearAuditProject::getEnterpriseId));
        List<IamWorkYearAuditProject> sumList = new ArrayList<>();
        map.forEach((key, value) ->
        {
            data.addAll(value);
            IamWorkYearAuditProject sum = new IamWorkYearAuditProject();
            sum.setAmount(0L);
            sum.setAuditProjectName("小计：");
            for (IamWorkYearAuditProject vo : value) {
                sum.setAmount(sum.getAmount() + vo.getAmount());
            }
            sumList.add(sum);
            data.add(sum);
        });

        IamWorkYearAuditProject end = new IamWorkYearAuditProject();
        end.setAmount(0L);
        end.setAuditProjectName("总计：");
        for (IamWorkYearAuditProject vo : sumList) {
            end.setAmount(end.getAmount() + vo.getAmount());
        }
        data.add(end);

        ReportVO reportVO = new ReportVO();
        reportVO
                /**
                 * 问题清单
                 */
                .addHeader(HeaderVO.builder().key("enterpriseName").title("企业名称").build())
                .addHeader(HeaderVO.builder().key("auditProjectName").title("项目名称").build())
                .addHeader(HeaderVO.builder().key("auditCategoryName").title("类型").build())
                .addHeader(HeaderVO.builder().key("amount").title("数量").build());

        reportVO.setData(data);
        ReportReturnVO reportReturnVO = new ReportReturnVO();
        reportReturnVO.setGrids(reportVO);
        R<ReportReturnVO> obj = new R<>(CommonCode.SUCCESS);
        obj.setPageData(reportReturnVO);
        return obj;
    }


    @Override
    public R<ReportReturnVO> rectifyListData(IamAuditRectifyVO auditRectifyVO) {

        String fillingYear = auditRectifyVO.getFillingYear();
        if (StringUtil.isEmpty(fillingYear)) {
            throw new MyRuntimeException(new ObjResult("年份不能为空"));
        }
        List<String> unitIds = auditRectifyVO.getUnitIds();

        if (CollectionUtil.isEmpty(unitIds)) {
            throw new MyRuntimeException(new ObjResult("企业不能为空"));
        }

        List<Map> result = new LinkedList<>();

        for (String unitId : unitIds) {
            //审计整改
            List<IamAuditRectify> auditRectifys = auditRectifyMapper.selectList(new LambdaQueryWrapper<IamAuditRectify>()
                    .eq(IamAuditRectify::getUnitId, unitId).like(IamAuditRectify::getFindIssueDate, fillingYear));
            if (CollectionUtil.isEmpty(auditRectifys)) {
                throw new MyRuntimeException(new ObjResult("未查询到该企业"));
            }
            if (CollectionUtil.isNotEmpty(auditRectifys)) {

                for (IamAuditRectify auditRectify : auditRectifys) {
                    Map<String, Object> map = new LinkedHashMap<>();
                    //问题清单
                    List<IamRectifyIssureList> rectifyIssures = issureListMapper.selectList(new LambdaQueryWrapper<IamRectifyIssureList>()
                            .eq(IamRectifyIssureList::getAuditRectifyId, auditRectify.getId()));
                    if (CollectionUtil.isNotEmpty(rectifyIssures)) {
                        IamRectifyIssureList rectifyIssure = rectifyIssures.get(0);
                        //问题清单
                        map.put("issure_domain", rectifyIssure.getIssureDomain());
                        Dict issureNatureDict = dictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, rectifyIssure.getIssureNature()));
                        map.put("issure_nature", issureNatureDict.getName());
                        map.put("issure_express", rectifyIssure.getIssureExpress());
                        map.put("find_issue_date", DateUtil.format(rectifyIssure.getFindIssueDate(), DateUtil.PATTERN_DATE));
                        map.put("unit_name", rectifyIssure.getUnitName());
                        map.put("qualitative_basis", rectifyIssure.getQualitativeBasis());
                        map.put("audit_process_opinion", rectifyIssure.getAuditProcessOpinion());
                        Dict rectifyTypeDict = dictMapper.selectOne(new LambdaQueryWrapper<Dict>().eq(Dict::getCode, rectifyIssure.getRectifyType()));
                        map.put("rectify_type", rectifyTypeDict.getName());
                        map.put("issure_source_report", rectifyIssure.getIssureSourceReport());
                        map.put("audit_report_num", rectifyIssure.getAuditReportNum());
                        map.put("issure_matters", rectifyIssure.getIssureMatters());

                    }
                    //目标清单
                    List<IamRectifyTargetList> rectifyTargets = targetListMapper.selectList(new LambdaQueryWrapper<IamRectifyTargetList>()
                            .eq(IamRectifyTargetList::getAuditRectifyId, auditRectify.getId()));
                    if (CollectionUtil.isNotEmpty(rectifyTargets)) {
                        IamRectifyTargetList rectifyTarget = rectifyTargets.get(0);

                        //目标清单
                        map.put("rectify_target", rectifyTarget.getRectifyTarget());
                        map.put("rectify_measure", rectifyTarget.getRectifyMeasure());
                        map.put("rectify_money", rectifyTarget.getRectifyMoney());
                        //责任清单
                        map.put("rectify_lead_dept", rectifyTarget.getRectifyLeadDept());
                        map.put("rectify_assist_dept", rectifyTarget.getRectifyAssistDept());
                        map.put("rectify_duty_unit", rectifyTarget.getRectifyDutyUnit());
                        map.put("urge_duty_unit", rectifyTarget.getUrgeDutyUnit());
                        map.put("urge_lead_duty_unit", rectifyTarget.getUrgeLeadDutyUnit());
                        map.put("definite_dept_mplements", rectifyTarget.getDefiniteDeptImplements());

                        //时限清单
                        map.put("plan_rectify_date", rectifyTarget.getPlanRectifyDate());

                    }
                    //整改清单
                    List<IamRectifyReformList> rectifyReforms = reformListMapper.selectList(new LambdaQueryWrapper<IamRectifyReformList>()
                            .eq(IamRectifyReformList::getAuditRectifyId, auditRectify.getId()));
                    if (CollectionUtil.isNotEmpty(rectifyReforms)) {
                        IamRectifyReformList rectifyReform = rectifyReforms.get(0);

                        // 整改清单
                        map.put("rectify_result", rectifyReform.getRectifyResult());
                        map.put("rectify_process_file", rectifyReform.getRectifyProcessFile());
                        map.put("rectify_source_measure", rectifyReform.getRectifySourceMeasure());
                        map.put("rectify_list_shift", rectifyReform.getRectifyListShift());

                        //成效清单
                        map.put("subtotal", rectifyReform.getSubtotal() == null ? null : rectifyReform.getSubtotal().setScale(2, RoundingMode.HALF_UP));
                        map.put("hand_amount", rectifyReform.getHandAmount() == null ? null : rectifyReform.getHandAmount().setScale(2, RoundingMode.HALF_UP));
                        map.put("receive_amount", rectifyReform.getReceiveAmount() == null ? null : rectifyReform.getReceiveAmount().setScale(2, RoundingMode.HALF_UP));
                        map.put("clear_amount", rectifyReform.getClearAmount() == null ? null : rectifyReform.getClearAmount().setScale(2, RoundingMode.HALF_UP));
                        map.put("disbursement_amount", rectifyReform.getClearAmount() == null ? null : rectifyReform.getDisbursementAmount().setScale(2, RoundingMode.HALF_UP));
                        map.put("other", rectifyReform.getOther());
                        map.put("party_process_type", rectifyReform.getPartyProcessType());
                        map.put("party_process_num", rectifyReform.getPartyProcessNum());
                        map.put("government_affairs_type", rectifyReform.getGovernmentAffairsType());
                        map.put("government_affairs_num", rectifyReform.getGovernmentAffairsNum());
                        map.put("form_duty_type", rectifyReform.getFormDutyType());
                        map.put("form_duty_num", rectifyReform.getFormDutyNum());
                        map.put("update_regulation_name", rectifyReform.getUpdateRegulationName());
                        map.put("update_regulation_num", rectifyReform.getUpdateRegulationNum());
                        map.put("new_regulation_name", rectifyReform.getNewRegulationName());
                        map.put("new_regulation_num", rectifyReform.getNewRegulationNum());
                        map.put("mana_system_name", rectifyReform.getManaSystemName());
                        map.put("mana_system_num", rectifyReform.getManaSystemNum());
                        map.put("other_name", rectifyReform.getOtherName());
                        map.put("other_num", rectifyReform.getOtherNum());

                    }

                    //认定清单
                    List<IamRectifyIdentifyList> rectifyIdentifys = identifyListMapper.selectList(new LambdaQueryWrapper<IamRectifyIdentifyList>()
                            .eq(IamRectifyIdentifyList::getAuditRectifyId, auditRectify.getId()));
                    if (CollectionUtil.isNotEmpty(rectifyIdentifys)) {
                        IamRectifyIdentifyList rectifyIdentify = rectifyIdentifys.get(0);
                        map.put("duty_unit_identify", rectifyIdentify.getDutyUnitIdentify());
                        map.put("lead_unit_identify", rectifyIdentify.getLeadUnitIdentify());
                        map.put("audit_dept_identify", rectifyIdentify.getAuditDeptIdentify());
                        map.put("rectify_dept_identify", rectifyIdentify.getRectifyDeptIdentify());
                        map.put("remark", rectifyIdentify.getRemark());
                    }
                    result.add(map);
                }

            }


        }
        //header

        List<HeaderVO> headerResult = new ArrayList<>();
        /**
         * 问题清单
         */
        List<HeaderVO> headerVOS1 = new ArrayList<>();
        List<HeaderVO> childHeadList1 = new ArrayList<>();
        List<HeaderVO> childSubHeadList1 = new ArrayList<>();
        childHeadList1.add(HeaderVO.builder().key("问题分类").title("问题分类").children(childSubHeadList1).build());
        childSubHeadList1.add(HeaderVO.builder().key("issure_domain").title("问题领域").build());
        childSubHeadList1.add(HeaderVO.builder().key("issure_nature").title("问题性质").build());
        childSubHeadList1.add(HeaderVO.builder().key("issure_express").title("问题表述").build());
        childHeadList1.add(HeaderVO.builder().key("find_issue_date").title("发现问题时间（年月）").build());
        childHeadList1.add(HeaderVO.builder().key("unit_name").title("发现问题单位").build());
        childHeadList1.add(HeaderVO.builder().key("issure_matters").title("问题涉及具体事项").build());
        childHeadList1.add(HeaderVO.builder().key("qualitative_basis").title("定型依据").build());
        childHeadList1.add(HeaderVO.builder().key("audit_process_opinion").title("审计处理意见").build());
        childHeadList1.add(HeaderVO.builder().key("rectify_type").title("整改类型").build());
        childHeadList1.add(HeaderVO.builder().key("issure_source_report").title("问题来源审计报告（名称）").build());
        childHeadList1.add(HeaderVO.builder().key("audit_report_num").title("审计报告（批示）文号").build());
        headerVOS1.add(HeaderVO.builder()
                .key("问题清单")
                .title("问题清单").children(childHeadList1).build());
        /**
         * 目标清单
         */
        List<HeaderVO> headerVOS2 = new ArrayList<>();
        List<HeaderVO> childHeadList2 = new ArrayList<>();
        childHeadList2.add(HeaderVO.builder().key("rectify_target").title("整改目标").build());
        childHeadList2.add(HeaderVO.builder().key("rectify_measure").title("整改措施").build());
        childHeadList2.add(HeaderVO.builder().key("rectify_money").title("其中涉及整改金额万元").build());
        headerVOS2.add(HeaderVO.builder()
                .key("目标清单")
                .title("目标清单").children(childHeadList2).build());
        /**
         * 责任清单
         */
        List<HeaderVO> headerVOS3 = new ArrayList<>();
        List<HeaderVO> childHeadList3 = new ArrayList<>();
        List<HeaderVO> childSubHeadList3_1 = new ArrayList<>();
        List<HeaderVO> childSubHeadList3_2 = new ArrayList<>();
        childHeadList3.add(HeaderVO.builder().key("整改责任").title("整改责任").children(childSubHeadList3_1).build());
        childHeadList3.add(HeaderVO.builder().key("督促责任").title("督促责任").children(childSubHeadList3_2).build());

        childSubHeadList3_1.add(HeaderVO.builder().key("rectify_lead_dept").title("整改牵头部门（联系人及电话）").build());
        childSubHeadList3_1.add(HeaderVO.builder().key("rectify_assist_dept").title("整改协助（配合）部门联系人及电话").build());
        childSubHeadList3_1.add(HeaderVO.builder().key("rectify_duty_unit").title("整改责任单位联系人及电话").build());
        childSubHeadList3_2.add(HeaderVO.builder().key("urge_lead_duty_unit").title("牵头（责任）部门联系人").build());
        childSubHeadList3_2.add(HeaderVO.builder().key("definite_dept_mplements").title("具体实施部门联系人").build());
        headerVOS3.add(HeaderVO.builder()
                .key("责任清单")
                .title("责任清单").children(childHeadList3).build());
        /**
         * 整改清单
         */
        List<HeaderVO> headerVOS4 = new ArrayList<>();
        List<HeaderVO> childHeadList4 = new ArrayList<>();
        childHeadList4.add(HeaderVO.builder().key("rectify_result").title("整改结果").build());
        childHeadList4.add(HeaderVO.builder().key("rectify_process_file").title("整改进程档案").build());
        childHeadList4.add(HeaderVO.builder().key("rectify_source_measure").title("整改未到位原因及下步措施").build());
        childHeadList4.add(HeaderVO.builder().key("rectify_list_shift").title("列入整改清单班次").build());
        headerVOS4.add(HeaderVO.builder()
                .key("整改清单")
                .title("整改清单").children(childHeadList4).build());
        /**
         * 时限清单
         */
        List<HeaderVO> headerVOS5 = new ArrayList<>();
        List<HeaderVO> childHeadList5 = new ArrayList<>();
        List<HeaderVO> childSubHeadList5_1 = new ArrayList<>();
        childHeadList5.add(HeaderVO.builder().key("整改时限").title("整改时限").children(childSubHeadList3_1).build());
        childSubHeadList5_1.add(HeaderVO.builder().key("plan_rectify_date").title("整改时限/计划完成整改时间").build());
        headerVOS5.add(HeaderVO.builder()
                .key("时限清单")
                .title("时限清单").children(childHeadList5).build());

        /**
         * 成效清单
         */
        List<HeaderVO> headerVOS6 = new ArrayList<>();
        List<HeaderVO> childHeadList6 = new ArrayList<>();
        List<HeaderVO> childSubHeadList6_1 = new ArrayList<>();
        List<HeaderVO> childSubHeadList6_2 = new ArrayList<>();
        List<HeaderVO> childSubHeadList6_3 = new ArrayList<>();
        childHeadList6.add(HeaderVO.builder().key("完成整改金额（万元）").title("完成整改金额（万元）").children(childSubHeadList6_1).build());
        childHeadList6.add(HeaderVO.builder().key("追责问责情况").title("追责问责情况").children(childSubHeadList6_2).build());
        childHeadList6.add(HeaderVO.builder().key("完善法规、制度或管理体制机制情况").title("完善法规、制度或管理体制机制情况").children(childSubHeadList6_3).build());
        childSubHeadList6_1.add(HeaderVO.builder().key("subtotal").title("小计").build());//no
        childSubHeadList6_1.add(HeaderVO.builder().key("hand_amount").title("上交资金").build());//no
        childSubHeadList6_1.add(HeaderVO.builder().key("receive_amount").title("调账、追、收回资金").build());//no
        childSubHeadList6_1.add(HeaderVO.builder().key("clear_amount").title("清退资金").build());//no
        childSubHeadList6_1.add(HeaderVO.builder().key("disbursement_amount").title("拨付落实资金").build());//no
        childSubHeadList6_1.add(HeaderVO.builder().key("other").title("其它").build());//no
        childSubHeadList6_2.add(HeaderVO.builder().key("party_process_type").title("党纪处理-处理类型").build());
        childSubHeadList6_2.add(HeaderVO.builder().key("party_process_num").title("党纪处理-人次").build());
        childSubHeadList6_2.add(HeaderVO.builder().key("government_affairs_type").title("政务处理-处理类型").build());
        childSubHeadList6_2.add(HeaderVO.builder().key("government_affairs_num").title("政务处理-人次").build());
        childSubHeadList6_2.add(HeaderVO.builder().key("form_duty_type").title("刑事类型").build());
        childSubHeadList6_2.add(HeaderVO.builder().key("form_duty_num").title("刑事人次").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("update_regulation_name").title("修改完善法规制-名称").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("update_regulation_num").title("修改完善法规制-数量").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("new_regulation_name").title("新颁布法规制度-名称").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("new_regulation_num").title("新颁布法规制度-数量").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("mana_system_name").title("管理体制、机制-名称").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("mana_system_num").title("管理体制、机制-数量").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("other_name").title("其它-名称").build());
        childSubHeadList6_3.add(HeaderVO.builder().key("other_num").title("其它-数量").build());

        headerVOS6.add(HeaderVO.builder()
                .key("成效清单")
                .title("成效清单").children(childHeadList6).build());

        /**
         * 整改认定
         */
        List<HeaderVO> headerVOS7 = new ArrayList<>();
        List<HeaderVO> childHeadList7 = new ArrayList<>();

        childHeadList7.add(HeaderVO.builder().key("duty_unit_identify").title("责任单位自我认定").build());
        childHeadList7.add(HeaderVO.builder().key("lead_unit_identify").title("牵头单位初步认定").build());
        childHeadList7.add(HeaderVO.builder().key("audit_dept_identify").title("审计部门审核认定").build());
        childHeadList7.add(HeaderVO.builder().key("rectify_dept_identify").title("整改督查部门复核审定").build());
        childHeadList7.add(HeaderVO.builder().key("remark").title("其它需要说明的事项").build());
        headerVOS7.add(HeaderVO.builder()
                .key("整改认定")
                .title("整改认定").children(childHeadList7).build());


        headerResult.addAll(headerVOS1);
        headerResult.addAll(headerVOS2);
        headerResult.addAll(headerVOS3);
        headerResult.addAll(headerVOS4);
        headerResult.addAll(headerVOS5);
        headerResult.addAll(headerVOS6);
        headerResult.addAll(headerVOS7);

        ReportVO reportVO = new ReportVO();
        reportVO.setHeader(headerResult);
        reportVO.setData(result);
        ReportReturnVO reportReturnVO = new ReportReturnVO();
        reportReturnVO.setGrids(reportVO);
        R<ReportReturnVO> obj = new R<>(CommonCode.SUCCESS);
        obj.setPageData(reportReturnVO);
        return obj;
    }

//    @Async("ttlExecutor")
//    @Override TODO DEL
//    public Future<ImportResult> importExcel(String progressId, InputStream inputStream) {
//        String progress = "progress";
//        String key = progressId + "#half:hour";
//        try {
//            byte[] bytes = IOUtils.toByteArray(inputStream);
//            InputStream stream = new ByteArrayInputStream(bytes);
//
//            List<Object> projectList = new ArrayList<>();
//            EasyExcel.read(stream)
//                    .registerReadListener(new PageReadListener<>(list -> projectList.addAll(list)))
//                    .head(IamAuditRectifyImportExcelBean.class)
//                    .sheet(1) // 或者 .sheet(0)
//                    .headRowNumber(6)
//                    .doRead();
//            ImportExcelUtil.filterEmpty(projectList);
//            //校验必填项等
////            if (!result.isSuccess()){
////                CacheUtil.put(progress, progress, key, result.getMsg());
////                return new AsyncResult<>(result);
////            }
//            //处理时间
//            transDataOrDict(projectList);
//
//            List<IamAuditRectify> rectifies = rectifyService.list();
//            List<IamRectifyIssureList> issureLists = issureListService.list();
//            List<IamRectifyTargetList> targetLists = targetListService.list();
//            List<IamRectifyReformList> reformLists = reformListService.list();
//            List<IamRectifyIdentifyList> identifyLists = identifyListService.list();
//
//            int count = 0;
//            int size = projectList.size();
//            for (Object readExcel : projectList) {
//                IamAuditRectifyImportExcelBean currReadExcel = (IamAuditRectifyImportExcelBean) readExcel;
//                IamRectifyIssureList issureListData = (IamRectifyIssureList) ImportExcelUtil.getEntityByExcelBean((IamAuditRectifyImportExcelBean) readExcel, new IamRectifyIssureList());
//                IamRectifyTargetList targetListData = (IamRectifyTargetList) ImportExcelUtil.getEntityByExcelBean((IamAuditRectifyImportExcelBean) readExcel, new IamRectifyTargetList());
//                IamRectifyReformList reformListData = (IamRectifyReformList) ImportExcelUtil.getEntityByExcelBean((IamAuditRectifyImportExcelBean) readExcel, new IamRectifyReformList());
//                IamRectifyIdentifyList identifyListData = (IamRectifyIdentifyList) ImportExcelUtil.getEntityByExcelBean((IamAuditRectifyImportExcelBean) readExcel, new IamRectifyIdentifyList());
//                //入库
//                try {
//                    List<IamRectifyIssureList> filterIssures = issureLists.stream().filter(item -> item.getUnitName().equals(issureListData.getUnitName()) && item.getIssureMatters().equals(issureListData.getIssureMatters()) &&
//                            item.getIssureSourceReport().equals(issureListData.getIssureSourceReport())).collect(Collectors.toList());
//                    if (CollectionUtil.isNotEmpty(filterIssures)) {
//                        IamRectifyIssureList currIssureList = filterIssures.get(0);
//                        Long auditRectifyId = currIssureList.getAuditRectifyId();
//                        BeanUtils.copyProperties(issureListData, currIssureList);
//                        currIssureList.setAuditRectifyId(auditRectifyId);
//                        currIssureList.setUpdateTime(new Date());
//                        currIssureList.setUpdateUser(TokenUtil.getTokenUserId());
//                        issureListMapper.updateById(currIssureList);
//
//                        IamRectifyTargetList currTargetList = targetLists.stream().filter(item -> item.getAuditRectifyId().equals(auditRectifyId)).collect(Collectors.toList()).get(0);
//                        BeanUtils.copyProperties(targetListData, currTargetList);
//                        currTargetList.setAuditRectifyId(auditRectifyId);
//                        currTargetList.setUpdateTime(new Date());
//                        currTargetList.setUpdateUser(TokenUtil.getTokenUserId());
//                        targetListMapper.updateById(currTargetList);
//
//                        IamRectifyReformList currReformList = reformLists.stream().filter(item -> item.getAuditRectifyId().equals(auditRectifyId)).collect(Collectors.toList()).get(0);
//                        BeanUtils.copyProperties(reformListData, currReformList);
//                        currReformList.setAuditRectifyId(auditRectifyId);
//                        currReformList.setUpdateTime(new Date());
//                        currReformList.setUpdateUser(TokenUtil.getTokenUserId());
//                        reformListMapper.updateById(currReformList);
//
//                        IamRectifyIdentifyList currIdentifyList = identifyLists.stream().filter(item -> item.getAuditRectifyId().equals(auditRectifyId)).collect(Collectors.toList()).get(0);
//                        BeanUtils.copyProperties(identifyListData, currIdentifyList);
//                        currIdentifyList.setAuditRectifyId(auditRectifyId);
//                        currIdentifyList.setUpdateTime(new Date());
//                        currIdentifyList.setUpdateUser(TokenUtil.getTokenUserId());
//                        identifyListMapper.updateById(currIdentifyList);
//
//                        IamAuditRectify currAuditRectify = rectifies.stream().filter(item -> item.getId().equals(auditRectifyId)).collect(Collectors.toList()).get(0);
//                        currAuditRectify.setFindIssueDate(StringUtils.isBlank(currReadExcel.getFindIssureDate()) ? null : DateUtil.parse(currReadExcel.getFindIssureDate(), DateUtil.PATTERN_DATE));
//                        currAuditRectify.setUpdateTime(new Date());
//                        currAuditRectify.setUpdateUser(TokenUtil.getTokenUserId());
//                        auditRectifyMapper.updateById(currAuditRectify);
//                    } else {
//                        IamAuditRectify auditRectify = new IamAuditRectify();
//                        auditRectify.setFindIssueDate(StringUtils.isBlank(currReadExcel.getFindIssureDate()) ? null : DateUtil.parse(currReadExcel.getFindIssureDate(), DateUtil.PATTERN_DATE));
//                        auditRectify.setRectifyStatus("1");
//                        auditRectify.setCode(formCodeService.getCode(FormTypeConstant.IAM_AUDIT_PROBLEM_RECTIFY_LIST));
//                        auditRectify.setFormType(String.valueOf(FormTypeConstant.IAM_AUDIT_PROBLEM_RECTIFY_LIST));
//                        auditRectify.setStatus(FormStatusConstant.UNREVIEWED);
//                        rectifyService.saveOrUpdate(auditRectify);
//
//                        IamRectifyIssureList issureList = issureListData;
//                        issureList.setAuditRectifyId(auditRectify.getId());
//                        issureList.setFindIssueDate(StringUtils.isBlank(currReadExcel.getFindIssureDate()) ? null : DateUtil.parse(currReadExcel.getFindIssureDate(), DateUtil.PATTERN_DATE));
//                        issureList.setStatus(FormStatusConstant.UNREVIEWED);
//                        issureListService.saveOrUpdate(issureList);
//
//                        IamRectifyTargetList targetList = targetListData;
//                        targetList.setAuditRectifyId(auditRectify.getId());
//                        targetList.setPlanRectifyDate(StringUtils.isBlank(currReadExcel.getFindIssureDate()) ? null : DateUtil.parse(currReadExcel.getFindIssureDate(), DateUtil.PATTERN_DATE));
//                        targetList.setStatus(FormStatusConstant.UNREVIEWED);
//                        targetListService.saveOrUpdate(targetList);
//
//                        IamRectifyReformList reformList = reformListData;
//                        reformList.setAuditRectifyId(auditRectify.getId());
//                        reformList.setStatus(FormStatusConstant.UNREVIEWED);
//                        reformListService.saveOrUpdate(reformList);
//
//                        IamRectifyIdentifyList identifyList = identifyListData;
//                        identifyList.setAuditRectifyId(auditRectify.getId());
//                        identifyList.setStatus(FormStatusConstant.UNREVIEWED);
//                        identifyListService.saveOrUpdate(identifyList);
//                    }
//                    count++;
//                    int value = count * 100 / size;
//                    CacheUtil.put(progress, progress, key, value + 100);
//                } catch (Exception e) {
//                    log.error(readExcel + "导入失败,{}");
//                    CacheUtil.put(progress, progress, key, readExcel + "导入失败");
//                    return new AsyncResult<>(new ImportResult(false, readExcel + "导入失败"));
//                }
//            }
//
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getStackTrace(e));
//            log.error("解析失败");
//            CacheUtil.put(progress, progress, key, "解析失败");
//            return new AsyncResult<>(new ImportResult(false, "解析失败"));
//        }
//        CacheUtil.put(progress, progress, key, "导入成功");
//        return new AsyncResult<>(new ImportResult(true, "导入成功"));
//    }
//
//    /**
//     * 处理导入时间
//     *
//     * @param projectList
//     */
//    private void transDataOrDict(List<Object> projectList) {
//        projectList.forEach(item -> {
//            IamAuditRectifyImportExcelBean curr = (IamAuditRectifyImportExcelBean) item;
//            String findIssureDate = curr.getFindIssureDate();
//            String planRectifyDate = curr.getPlanRectifyDate();
//            if (StringUtil.isNotBlank(findIssureDate)) {
//                curr.setFindIssureDate(setRightDate(findIssureDate));
//            }
//            if (StringUtil.isNotBlank(planRectifyDate)) {
//                curr.setPlanRectifyDate(setRightDate(planRectifyDate));
//            }
//        });
//
//    }
//
//    @Override
//    public void exportTemplateExcel(HttpServletResponse response, OutputStream os) {
//        try {
//            String fname = "审计整改导入模板";
//            os = response.getOutputStream();//取得输出流
//            response.reset();//清空输出流
//            //下面是对中文文件名的处理
//            response.setCharacterEncoding("UTF-8");//设置相应内容的编码格式
//            InputStream inputStream = this.getClass().getResourceAsStream("/exceldemo/审计整改导入模版.xlsx");
//            fname = java.net.URLEncoder.encode(fname, "UTF-8");
//            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fname.getBytes("UTF-8"), "UTF-8") + ".xlsx");
//
//            response.setContentType("application/msexcel");//定义输出类型
//            int len;
//            byte[] b = new byte[2048];
//            while ((len = inputStream.read(b)) != -1) {
//                os.write(b, 0, len);
//            }
//            response.setHeader("Content-Length", String.valueOf(inputStream.available()));
//
//            inputStream.close();
//            os.close();
//        } catch (Exception e) {
//            log.error(ExceptionUtils.getFullStackTrace(e));
//        }
//    }
//
//    /**
//     * 处理导入时间
//     *
//     * @param dateStr
//     * @return
//     */
//    private String setRightDate(String dateStr) {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月");
//        try {
//            Date date = format.parse(dateStr);
//            return DateUtil.format(date, DateUtil.PATTERN_DATETIME);
//        } catch (ParseException e) {
//            throw new RuntimeException(e);
//        }
//
//    }

}
